package my.xh.validate.handler.impl;

import my.xh.validate.ValidateField;
import my.xh.validate.handler.ValidateHandler;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @ClassName NotNullValidateHandler
 * @Date 2019/1/17 14:51
 * @Author xuanhu
 * @Description 不为空的校验
 */
@Component
public class NotNullValidateHandler implements ValidateHandler {
    @Override
    public boolean validate(ValidateField validateField, StringBuilder paramName, Object paramValue, Map<String, Object> map,boolean flag) {
        if (validateField.notNull()) {  // 判断参数是否为空
            if (paramValue == null ) {
                flag = false;
                if(StringUtils.isEmpty(validateField.msg()))
                map.put(paramName.toString(), getMsg(validateField, paramName.append(" 不能为空").toString()));
            }
            if ( "".equals(paramValue) ) {
                flag = false;
                map.put(paramName.toString(), getMsg(validateField,paramName.append(" 不能为空字符串").toString()));
            }
        }
        return flag;
    }
}
